package watcher

import "fmt"

// convertBytes 将字节转换为更易读的格式
func convertBytes(size int64) string {
	const (
		KB = 1024
		MB = KB * 1024
		GB = MB * 1024
	)

	var sizeStr string

	if size >= GB {
		sizeStr = fmt.Sprintf("%.2fGB", float64(size)/GB)
	} else if size >= MB {
		sizeStr = fmt.Sprintf("%.2fMB", float64(size)/MB)
	} else if size >= KB {
		sizeStr = fmt.Sprintf("%.2fKB", float64(size)/KB)
	} else {
		sizeStr = fmt.Sprintf("%dB", size)
	}

	return sizeStr
}
